package com.mall.b2c.plugin.search;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.mall.b2c.domain.goods.GoodsCategoryDomain;
import com.mall.b2c.enums.PrescribeType;
import com.mall.b2c.util.DictionaryUtils;
import com.mall.common.hibernate.Finder;
import com.mall.common.plugin.AutoRegisterPlugin;
import com.mall.common.util.UrlUtils;
/**
 * 商品剂型筛选器
 * @author wangzx
 *
 */
public class PrescribeTypeSearchFilter {//extends AutoRegisterPlugin implements IGoodsSearchFilter{

	/*@Override
	public void filter(Finder finder, GoodsCategoryDomain cat, String urlFragment) {
		if(StringUtils.isNotBlank(urlFragment)) {
			PrescribeType prescribeType = null;
			try {
				prescribeType = PrescribeType.valueOf(urlFragment);
			} catch(IllegalArgumentException e) {
				e.printStackTrace();
			}
			if(prescribeType != null) {
				finder.append( " and g.prescribeType = :prescribeType");
				finder.setParam("prescribeType", prescribeType);
			}
		}
	}

	@Override
	public List<SearchSelector> createSelectorList(GoodsCategoryDomain cat, String url, String urlFragment, Map<String, String> paramMap,
			String hql, Finder finder) {
		List<SearchSelector> searchSelectors = new ArrayList<SearchSelector>();
		*//**已选择*//*
		if(StringUtils.isNotBlank(urlFragment)) {
			PrescribeType prescribeType = PrescribeType.valueOf(urlFragment);
			if(prescribeType != null){
				SearchSelector searchSelector = new SearchSelector();
				searchSelector.setName(DictionaryUtils.getEnumName(prescribeType));
				searchSelector.setSelected(Boolean.TRUE);
				searchSelector.setUrl(url);
				searchSelectors.add(searchSelector);
				return searchSelectors;
			}
		}
		*//**未选择*//*
		finder.resetHQL("select g.prescribeType, count(*) from " + hql + "group by g.prescribeType");
		List<Object[]> resultList = finder.findHQLList();
		for(Object[] rs : resultList) {
			PrescribeType prescribeType = rs[0] != null ? (PrescribeType)rs[0] : null;
			if(prescribeType == null) {
				continue;
			}
			SearchSelector searchSelector = new SearchSelector();
			searchSelector.setName(DictionaryUtils.getEnumName(prescribeType));
			searchSelector.setCount((Long)rs[1]);
			searchSelector.setUrl(UrlUtils.addUrlParam(url, getFilterId(), prescribeType.name(), false));
			searchSelector.setSelected(Boolean.FALSE);
			searchSelectors.add(searchSelector);
		}
		return searchSelectors;
	}

	@Override
	public String getFilterId() {
		return "prescribeType";
	}

	@Override
	public String getSysId() {
		return "prescribeTypeList";
	}

	@Override
	public String getType() {
		return "goodsSearchFilter";
	}

	@Override
	public String getId() {
		return "prescribeTypeSearchFilter";
	}

	@Override
	public String getName() {
		return "商品处方类型筛选器";
	}

	@Override
	public String getVersion() {
		return "1.0";
	}

	@Override
	public String getAuthor() {
		return "wangzx";
	}

	@Override
	public void perform(Object... params) {
		
	}

	@Override
	public void register() {
		
	}*/
}
